// 用于暂时模拟登陆测试
import PcCookie from '../../utils/pcCookie'
import  { gbs, cbs, enums }  from '../../utils/settings'
PcCookie.set({
  key: enums.USER.REDIRECT_URI,
  value: window.location.href
});

// 更新token
export let updateAuthToken = function(authToken) {
  // https://github.com/js-cookie/js-cookie/wiki/Frequently-Asked-Questions#expire-cookies-in-less-than-a-day
  let expires = 2 / 24;
  let isRemember = !!PcCookie.get(enums.USER.REMEMBER_ME);
  if (isRemember) {
    expires = 7;
  }
  // debugger;
  delete authToken['jti'];
  delete authToken['token_type'];
  let refreshToken = {};
  Object.assign(refreshToken, authToken);
  // delete authToken['scope'];
  delete authToken['refresh_token'];
  delete refreshToken['access_token'];

  PcCookie.set({
    key: enums.USER.AUTH_TOKEN,
    value: authToken,
    expires: expires
  });
  PcCookie.set({
    key: enums.USER.REFRESH_TOKEN,
    value: refreshToken,
    expires: expires
  });
}
// 获取token
export let getToken = function(name) {
  let authToken = PcCookie.get(enums.USER.AUTH_TOKEN);
  return authToken;
}

// 删除用户信息
export let delToken = function() {
  PcCookie.delete({
    key: enums.USER.AUTH_TOKEN
  });
  PcCookie.delete({
    key: enums.USER.LOGIN_NAME
  });
  PcCookie.delete({
    key: enums.USER.REMEMBER_ME
  });
  // window.history.go(0);
}
